package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCarController {

    @Resource
    private ShoppingCartService shoppingCartService;

    /**
     * 添加购物车
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        //如果新加的菜品(菜品id有值)
        shoppingCartService.add(shoppingCartDTO);
        //如果新加的套餐(套餐id有值)
        return Result.success();
    }

    /**
     * 展示购物车
     * @return
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> selectShoppingCart(){
        return Result.success(shoppingCartService.selectShoppingCart());
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public Result empty(){
        shoppingCartService.emptyShoppingCart();
        return Result.success();
    }

    /**
     * 单个删除
     */
    @PostMapping("/sub")
    public Result updateShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO ){
        shoppingCartService.updateShoppingCart(shoppingCartDTO);
        return Result.success();
    }
}
